// 引入库
let koa = require('koa')
let serve = require('koa-static')
let {historyApiFallback} = require('koa2-connect-history-api-fallback');
const proxy = require('koa2-proxy-middleware')


// 创建服务器
let app = new koa()

// 处理路径 404 问题的中间件
app.use(historyApiFallback())

// 代理转发请求  因为没有了vue脚手架,所以要解决跨域
app.use(proxy({
    targets: {
      // (.*) means anything
      '/prod-api/(.*)': {
          target: 'http://ihrm-java.itheima.net/api', //后端服务器地址
          changeOrigin: true,
          pathRewrite: { 	
              '/prod-api': ""
          }
      }
    }
  }))

app.use(serve(__dirname + "/public")); //将public下的代码静态化

//  开启服务器监听端口
app.listen(8011,()=>{
    console.log('服务器开启成功');
})